{% extends 'base.html' %}
{% from 'comments.html' import render_comments %}

{% block content %}
<div class="container">
    <article class="blog-post" data-post-id="{{ post.id }}">
        <h1 class="blog-post-title">{{ post.title }}</h1>
        <p class="blog-post-meta">
            {{ post.created_at.strftime('%Y-%m-%d %H:%M') }} by {{ post.author.name }}
            {% if post.category %}
            <span class="badge badge-secondary">{{ post.category }}</span>
            {% endif %}
        </p>

        <div class="blog-post-content">
            {{ post.content_html|safe }}
        </div>

        {% if current_user == post.author %}
        <div class="mt-4">
            <a href="{{ url_for('edit_post', post_id=post.id) }}" class="btn btn-primary">编辑</a>
            <form action="{{ url_for('delete_post', post_id=post.id) }}" method="post" class="d-inline">
                <button type="submit" class="btn btn-danger" onclick="return confirm('确定要删除这篇文章吗？')">删除</button>
            </form>
        </div>
        {% endif %}
    </article>
    
    <!-- 添加评论区 -->
    {{ render_comments(comments, current_user) }}
</div>
{% endblock %}
